package online.hxstart.code.concurrent.chapter06;

import java.util.concurrent.TimeUnit;

/**
 * @author huxing
 * @date 19-5-31 星期五 下午5:08
 * @describe threadGroup 基本操作
 */
public class ThreadGRoupBasic {

  public static void main(String[] args) throws InterruptedException {
    ThreadGroup group = new ThreadGroup("group1");

    Thread thread = new Thread(group, () -> {
      while (true) {
        try {
          TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }, "myThread");

    thread.setDaemon(true);
    thread.start();

    TimeUnit.MILLISECONDS.sleep(1);

    ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();

    System.out.println("activeCount=" + mainGroup.activeCount());
    System.out.println("activeGroupCount=" + mainGroup.activeGroupCount());
    System.out.println("getMaxPriority=" + mainGroup.getMaxPriority());
    System.out.println("getName=" + mainGroup.getName());
    System.out.println("getParent=" + mainGroup.getParent());

    mainGroup.list();

    System.out.println("--------------------------");
    System.out.println("parentOf=" + mainGroup.parentOf(group));
    System.out.println("parentOf=" + mainGroup.parentOf(mainGroup));
  }
}
